package com.asa.mvvm_aop_frame.basic

import android.app.Activity
import android.os.Bundle
import android.view.WindowManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent

/**
 * create By：anderson
 * on 2022/4/24
 * desc:
 */
interface BaseContract {


    interface IApplication {

        fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        }

        fun onActivityStarted(activity: Activity) {
        }

        fun onActivityResumed(activity: Activity) {
        }

        fun onActivityPaused(activity: Activity) {
        }

        fun onActivityStopped(activity: Activity) {
        }

        fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
        }

        fun onActivityDestroyed(activity: Activity) {
        }

        /**
         * 应用退到后台
         * @param activity Activity
         */
        fun toBackground(activity: Activity) {}

        /**
         * 应用回到前台
         * @param activity Activity
         */
        fun toForeground(activity: Activity) {}




        /**
         * 异常捕获，本地默认dump到本地
         * @param ex Throwable
         */
        fun crashOpera(ex: Throwable) {}
    }

    interface IView {

        /**
         *  需要重写的布局id
         */
        fun getLayoutId(): Int



        /**
         * 在setContentView之前执行，可以进行window.addTag等相关操作
         */
        fun initParams() {}

        /**
         *xml中viewModel的id，建议都用viewModel，例如： name="viewModel"
         */
        fun initVariableId():Int

        /**
         * 初始化view
         * @param savedInstanceState Bundle?
         */
        fun initView(savedInstanceState: Bundle?)



        /**
         * 初始化一些基本数据，viewModel已绑定生命周期，建议本地数据或者网络数据在viewModel生命周期中执行
         */
        fun initData()

        /**
         * 初始化LiveData或者DataBinding的ObservableField之类的监听
         */
        fun initViewObservable()
    }


    interface IWindow {

        /**
         *  窗口动画  默认没有
         */
        fun windowAnimations():Int ?= null

    }

    /**
     * 用于BaseActivity实现--状态栏、导航栏、软键盘等系统层
     */
    interface IBar {
        /**
         * 是否开启沉浸式
         *
         * @return
         */
        fun immersionBarEnabled(): Boolean = true

        /**
         * 沉浸式下是否全屏
         *
         * @return
         */
        fun isFullScreen(): Boolean = false

        /**
         * 是否fitsSystemWindows
         *
         * @return
         */
        fun fitsSystemWindows(): Boolean = true

        /**
         * 沉浸式非全屏下状态栏字体是否深色
         *
         * @return
         */
        fun statusBarDarkFont(): Boolean = true


        /**
         * 沉浸式非全屏下状态栏背景颜色
         *
         * @return
         */
        fun statusBarColor(): Int = R.color.white

        /**
         * 沉浸式非全屏下底部导航栏背景颜色
         *
         * @return
         */
        fun navigationBarColor(): Int = R.color.black_trans

        /**
         * 是否隐藏底部导航栏
         * @return Boolean
         */
        fun hideNavigationBar(): Boolean = true

        /**
         * 解决EditText与软键盘冲突
         *
         * @return true：EditText跟随软键盘弹起，false反之
         */
        fun keyboardEnable(): Boolean = true

        /**
         * 软键盘模式
         *
         * @return
         */
        fun keyboardMode(): Int = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE

        /**
         * 软键盘监听
         * @param isPopup Boolean 是否弹起
         * @param keyboardHeight Int 弹起高度
         */
        fun onKeyboardChange(isPopup: Boolean, keyboardHeight: Int) {}
    }

    interface IViewModel:LifecycleObserver{

        @OnLifecycleEvent(Lifecycle.Event.ON_ANY)
        fun onAny(owner: LifecycleOwner?, event: Lifecycle.Event?) {
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
        fun onCreate() {
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        fun onDestroy() {
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_START)
        fun onStart() {
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
        fun onStop() {
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
        fun onResume() {
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
        fun onPause() {
        }
    }
}